﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;

namespace 客户端版本生成
{
    public partial class clientvision : Form
    {
        string _OpenPath;
        string _SavePath;
        XmlDocument clientinfo = new XmlDocument();
        public clientvision()
        {
            InitializeComponent();
        }

        private void GenerateButton_Click(object sender, EventArgs e)
        {
            XmlElement NRoot;
            XmlNode xmlNode;
            xmlNode = clientinfo.CreateNode(XmlNodeType.XmlDeclaration, "", "");
            clientinfo.AppendChild(xmlNode);
            NRoot = clientinfo.CreateElement("ClientInfo");
            clientinfo.AppendChild(NRoot);

            XmlElement clientfile;
            XmlText clientfiletext;
            clientfile = clientinfo.CreateElement("Name");
            clientfiletext = clientinfo.CreateTextNode(FileTextBox.Text);
            clientfile.AppendChild(clientfiletext);
            NRoot.AppendChild(clientfile);

            XmlElement clientversion;
            XmlText clientversiontext;
            clientversion = clientinfo.CreateElement("Version");
            clientversiontext = clientinfo.CreateTextNode(VersionTextBox.Text);
            clientversion.AppendChild(clientversiontext);
            NRoot.AppendChild(clientversion);

            XmlElement clientversiondate;
            XmlText clientversiondatetext;
            clientversiondate = clientinfo.CreateElement("VersionDate");
            clientversiondatetext = clientinfo.CreateTextNode(VersionDateTextBox.Text);
            clientversiondate.AppendChild(clientversiondatetext);
            NRoot.AppendChild(clientversiondate);

            XmlElement clientXML;
            XmlText clientXMLtext;
            clientXML = clientinfo.CreateElement("XML");
            clientXMLtext = clientinfo.CreateTextNode(SeverLocationText.Text);
            clientXML.AppendChild(clientXMLtext);
            NRoot.AppendChild(clientXML);

            saveFileDialog1.ShowDialog();


        }

        private void BrowseButton_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            _OpenPath = openFileDialog1.FileName;
//             FileVersionInfo myFileVersion = FileVersionInfo.GetVersionInfo(_OpenPath);
//             string strFileVersion = string.Format("{0}.{1}.{2}.{3}",
//                 myFileVersion.FileMajorPart, myFileVersion.FileMinorPart,
//                 myFileVersion.FileBuildPart, myFileVersion.FilePrivatePart);
//             VisionTextBox.Text = strFileVersion;
            FileTextBox.Text = Path.GetFileName(_OpenPath).Remove(Path.GetFileName(_OpenPath).LastIndexOf("."));
        }

        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            _SavePath = saveFileDialog1.FileName;
            clientinfo.Save(_SavePath);
            MessageBox.Show("保存xml成功，请和update.exe放在同意目录", "保存成功", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }
    }
}
